package org.example.mallchat.exception;

import lombok.extern.slf4j.Slf4j;
import org.example.mallchat.common.domain.vo.ApiResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 * @author <a href="https://gitee.com/zzhpalus">zzhKing</a>
 * @from <a href="https://gitee.com/zzhpalus">致力于学习</a>
 */
@RestControllerAdvice//针对所有@RestController注解的接口类进行捕获异常处理
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ApiResult<?> businessExceptionHandler(BusinessException e) {
        log.error("BusinessException", e);
        return ApiResult.fail(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public ApiResult<?> runtimeExceptionHandler(RuntimeException e) {
        log.error("RuntimeException", e);
        return ApiResult.fail(ErrorCode.SYSTEM_ERROR.getCode(), "系统错误");
    }

//    @ExceptionHandler(NotLoginException.class)
//    public ApiResult<?> NotLoginExceptionHandler(RuntimeException e) {
//        log.error("RuntimeException", e);
//        return ApiResult.fail(40101, "未登录");
//    }


}
